package cn.echoedu.specifics;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;

import cn.echoedu.daoconstants.TableName;
import cn.echoedu.entity.Department;
import cn.echoedu.entity.SchoolNotify;
import cn.echoedu.entity.Teacher;
import cn.echoedu.util.DateUtil;
import cn.echoedu.util.L;
import cn.echoedu.util.StringUtil;

public class SpecSchoolNotify extends BaseSpec{
   private final String T = "SpecSchoolNotify-------->>";
	@Override
	public <T> PreparedStatement getPreparedInsert(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		SchoolNotify schoolnotify = (SchoolNotify)currentPojo;
		String sql =  "insert into schoolnotify values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
	    PreparedStatement preparedstatement = con.prepareStatement(sql);
        preparedstatement.setInt(1,schoolnotify.getSchoolnotifyid());
        preparedstatement.setString(2,schoolnotify.getTitle());
        preparedstatement.setString(3,schoolnotify.getPlace());
        preparedstatement.setString(4,schoolnotify.getContent());
        preparedstatement.setString(5,schoolnotify.getFilepath());
        preparedstatement.setTimestamp(6,(Timestamp) schoolnotify.getStarttime());
        preparedstatement.setTimestamp(7,(Timestamp) schoolnotify.getEndtime());
        preparedstatement.setTimestamp(8,(Timestamp) schoolnotify.getRemindertime());
        preparedstatement.setInt(9,schoolnotify.getShowinhomepage());
        preparedstatement.setInt(10,schoolnotify.getHitcount());
        preparedstatement.setTimestamp(11,(Timestamp) schoolnotify.getPublishtime());
        preparedstatement.setInt(12, schoolnotify.getDepartment().getDepartmentcode());
        preparedstatement.setInt(13,schoolnotify.getLikenum());
        preparedstatement.setInt(14,schoolnotify.getDislikenum());
        return preparedstatement;
	}
	@Override
	public <T> PreparedStatement getPreparedInsertRunning(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		String sql = "insert into schoolnotify(title,place,content,filepath," +
				"starttime,endtime,remindertime,showinhomepage,hitcount," +
				"publishtime,teachernumber,schoolcode) values(";
		return null;
	}

	@Override
	public Object getPojo(ResultSet rs) throws SQLException {
		// TODO Auto-generated method stub
		SchoolNotify schoolnotify = new SchoolNotify();
		schoolnotify.setSchoolnotifyid(rs.getInt(1));
		schoolnotify.setTitle(rs.getString(2));
		schoolnotify.setPlace(rs.getString(3));
		schoolnotify.setContent(rs.getString(4));
		schoolnotify.setFilepath(rs.getString(5));
		schoolnotify.setStarttime(rs.getTimestamp(6));
		schoolnotify.setEndtime(rs.getTimestamp(7));
		schoolnotify.setRemindertime(rs.getTimestamp(8));
		schoolnotify.setShowinhomepage(rs.getInt(9));
		schoolnotify.setHitcount(rs.getInt(10));
		schoolnotify.setPublishtime(rs.getTimestamp(11));
		Teacher teacher = new Teacher();
		teacher.setTeachernumber(rs.getString(12));
		schoolnotify.setTeacher(teacher);
		Department department = new Department();
		department.setDepartmentcode(rs.getInt(13));
		schoolnotify.setDepartment(department);
		schoolnotify.setLikenum(rs.getInt(14));
		schoolnotify.setDislikenum(rs.getInt(15));
		return schoolnotify;
	}

	@Override
	public <T> PreparedStatement getPreparedUpdate(Connection con,
			TableName tableName, T oldPojo, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		SchoolNotify oldschoolnotify = (SchoolNotify)oldPojo;
		SchoolNotify newschoolnotify = (SchoolNotify)currentPojo;
		String sql = "update schoolnotify set title=?,place=?,content=?,filepath=?," +
				"starttime=?,endtime=?,remindertime=?,showinhomepage=?,hitcount=?," +
				"publishtime=?,teachernumber=?,departmentcode=?,likenum=?,dislikenum=?" +
				" where schoolnotifyid=?";
		PreparedStatement preparedstatement = con.prepareStatement(sql);
		preparedstatement.setString(1,oldschoolnotify.getTitle());
		preparedstatement.setString(2,oldschoolnotify.getPlace());
		preparedstatement.setString(3,oldschoolnotify.getContent());
		preparedstatement.setString(4,oldschoolnotify.getFilepath());
		preparedstatement.setTimestamp(5, oldschoolnotify.getStarttime());
		preparedstatement.setTimestamp(6,oldschoolnotify.getEndtime());
		preparedstatement.setTimestamp(7,oldschoolnotify.getRemindertime());
		preparedstatement.setInt(8,oldschoolnotify.getShowinhomepage());
		preparedstatement.setInt(9,oldschoolnotify.getHitcount());
		preparedstatement.setTimestamp(10, oldschoolnotify.getPublishtime());
		preparedstatement.setString(11,oldschoolnotify.getTeacher().getTeachernumber());
		preparedstatement.setInt(12,oldschoolnotify.getDepartment().getDepartmentcode());
		preparedstatement.setInt(13,oldschoolnotify.getLikenum());
		preparedstatement.setInt(14,oldschoolnotify.getDislikenum());
		preparedstatement.setInt(15,newschoolnotify.getSchoolnotifyid());
		return preparedstatement;
	}

	@Override
	public Object getLeftJoinPojo(ResultSet rs) throws SQLException {
		// TODO Auto-generated method stub
		SchoolNotify schoolnotify = new SchoolNotify();
		schoolnotify.setSchoolnotifyid(rs.getInt(1));
		
		schoolnotify.setTitle(rs.getString(2));
		L.p("@@@@@"+schoolnotify.getTitle());
		schoolnotify.setPlace(rs.getString(3));
		schoolnotify.setContent(rs.getString(4));
		schoolnotify.setFilepath(rs.getString(5));
		schoolnotify.setStarttime(rs.getTimestamp(6));
		schoolnotify.setEndtime(rs.getTimestamp(7));
		schoolnotify.setRemindertime(rs.getTimestamp(8));
		schoolnotify.setShowinhomepage(rs.getInt(9));
		schoolnotify.setHitcount(rs.getInt(10));
		schoolnotify.setPublishtime(rs.getTimestamp(11));
		Teacher teacher = new Teacher();
		teacher.setTeachernumber(rs.getString(12));
		schoolnotify.setTeacher(teacher);
		Department department = new Department();
		department.setDepartmentcode(rs.getInt(13));
		schoolnotify.setDepartment(department);
		schoolnotify.setLikenum(rs.getInt(14));
		schoolnotify.setDislikenum(rs.getInt(15));
		return schoolnotify;
	}

	@Override
	public Object getPojoBySql(ResultSet rs) throws SQLException {
		// TODO Auto-generated method stub
		SchoolNotify schoolnotify = new SchoolNotify();
		schoolnotify.setSchoolnotifyid(rs.getInt("schoolnotify.schoolnotifyid"));
		schoolnotify.setTitle(rs.getString("schoolnotify.title"));
		L.p("@@@@@"+schoolnotify.getTitle());
		schoolnotify.setPlace(rs.getString("schoolnotify.place"));
		schoolnotify.setContent(rs.getString("schoolnotify.content"));
		schoolnotify.setFilepath(rs.getString("schoolnotify.filepath"));
		schoolnotify.setStarttime(rs.getTimestamp("schoolnotify.starttime"));
		schoolnotify.setEndtime(rs.getTimestamp("schoolnotify.endtime"));
		schoolnotify.setRemindertime(rs.getTimestamp("schoolnotify.remindertime"));
		schoolnotify.setShowinhomepage(rs.getInt("schoolnotify.showinhomepage"));
		schoolnotify.setHitcount(rs.getInt("schoolnotify.hitcount"));
		schoolnotify.setPublishtime(rs.getTimestamp("schoolnotify.publishtime"));
		Teacher teacher = new Teacher();
		teacher.setTeachernumber(rs.getString("schoolnotify.teachernumber"));
		schoolnotify.setTeacher(teacher);
		Department department = new Department();
		department.setDepartmentcode(rs.getInt("schoolnotify.departmentcode"));
		schoolnotify.setDepartment(department);
		schoolnotify.setLikenum(rs.getInt("schoolnotify.likenum"));
		schoolnotify.setDislikenum(rs.getInt("schoolnotify.dislikenum"));
		return schoolnotify;
	}

	@Override
	public <T> String getPreparedInsertGetPrimaryKeySql(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		final String M ="getPreparedInsertGetPrimaryKeySql*******>>";
		L.p(T+M);
		SchoolNotify schoolnotify = (SchoolNotify)currentPojo;
		String sql =  " insert into schoolnotify (title,place,content,filepath," +
				"starttime, endtime, remindertime,showinhomepage,hitcount," +
				"publishtime,teachernumber,departmentcode,likenum,dislikenum) "+
				"  values"+StringUtil.getBeforeTheBsrackets()+StringUtil.varToSqlObject(schoolnotify.getTitle())
				+StringUtil.getComma()+StringUtil.varToSqlObject(schoolnotify.getPlace())
				+StringUtil.getComma()+StringUtil.varToSqlObject(schoolnotify.getContent())
				+StringUtil.getComma()+StringUtil.varToSqlObject(schoolnotify.getFilepath())
				+StringUtil.getComma()+StringUtil.varToSqlObject(DateUtil.dateToString(schoolnotify.getStarttime()))
				+StringUtil.getComma()+StringUtil.varToSqlObject(DateUtil.dateToString(schoolnotify.getEndtime()))
				+StringUtil.getComma()+StringUtil.varToSqlObject(DateUtil.dateToString( schoolnotify.getRemindertime()))
				+StringUtil.getComma()+StringUtil.varToSqlObject(schoolnotify.getShowinhomepage())
				+StringUtil.getComma()+StringUtil.varToSqlObject(schoolnotify.getHitcount())
				+StringUtil.getComma()+StringUtil.varToSqlObject(DateUtil.dateToDetailString( schoolnotify.getPublishtime()))
				+StringUtil.getComma()+StringUtil.varToSqlObject(schoolnotify.getTeacher().getTeachernumber())
				+StringUtil.getComma()+StringUtil.varToSqlObject(schoolnotify.getDepartment().getDepartmentcode())
				+StringUtil.getComma()+StringUtil.varToSqlObject(schoolnotify.getLikenum())
				+StringUtil.getComma()+StringUtil.varToSqlObject(schoolnotify.getDislikenum())
				+StringUtil.getAfterTheBrackets();
		L.p(T+M+sql);
		return sql;
	}
	@Override
	public <T> PreparedStatement getPreparedListInsert(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public <T> PreparedStatement getPreparedListInsertRunning(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

}
